<?php
class ControllerCommonEnvironmental extends Controller {   
public function index(){ 
		
        $this->load->model('catalog/information');
        $this->template = 'common/environmental.tpl';
		$arrayenv=array("Geographical Strees (GS)","Negative Ultra Voilet (-UV)","Infrared radiation","Sole Devils D (-UV &amp; -IR )");
		$arrayplant=array("The Sun (Surya)","Mercury (Moon)","Venus (Khuja)","Earth (Budha)","Mars (Guru)","Jupiter (Sukhara)","Saturn (Sani)","Uranus (Rahu)","Neptune (Kethu)");
		$arraychacra=array("Muladhra","Swadhistana","Naval","Solar Plexus","Front Head","Back Head","Throat","Ajna","Fore Head","Crown","Spleen");
		

		$this->load->model('catalog/checkingform');
		
		if(isset($_POST))
		{
			$uid=base64_decode($_GET['uid']);
			$before=$_POST['before'];
			$environ=$_POST;
			$userdetailes=$this->model_catalog_checkingform->addEnvDetailes($uid,$before,$environ);
		}
		if(isset($_GET['before']) || isset($_GET['after']))
		{ 
			$uid=base64_decode($_GET['uid']);
			if($_GET['before']==1)
			{
				$position=1;
			}
			else if($_GET['after']==1)
			{
				$position=2;
			}
			
			$userdetailes=$this->model_catalog_checkingform->userDetails($uid);
			
		    $this->data['uname']=$userdetailes['name'];
			$this->data['chackradetails']=array();
			$this->data['plantdetails']=array();
			$this->data['envdetails']=array();
			$this->data['isexists']="";
		    $envArr = array();
			$plantArr =  array();
			$chakraArr =  array();
			foreach($arrayenv as $envarray)
			{
				$envdetails[$envarray]=$this->model_catalog_checkingform->getenvdetails($uid,$envarray,$position);
			}
			$envArr1[] = '';
			$envArr2[] = '';
			foreach($envdetails as $envData) 
			{
				if($envData['lowangel'] != 0 || $envData['yes']== 'yes') {
				   if($envData['lowangel'] != 0) {
						$envValue = $envData['lowangel'];
				   } else {
						$envValue = 100;
				   }
				   $envArr1[] = $envData['environmental'];
				   $envArr2[] = (float)$envValue;
				}
			}

			foreach($arrayplant as $plantarray)
			{
				$plantdetails[$plantarray]=$this->model_catalog_checkingform->getplantdetails($uid,$plantarray,$position);
			}
				
			$plantArr1[] = '';
			$plantArr2[] = '';
			foreach($plantdetails as $plantData) 
			{
					   if($plantData['lowangel'] != 0 || $plantData['hle'] == 'HLE') {
						   if($plantData['lowangel'] != 0) {
								$plantValue = $plantData['lowangel'];
						   } else {
								$plantValue = 100;
						   }
						$plantArr1[] = $plantData['planetray'];
						$plantArr2[] = (float)$plantValue;
				}
			}
			foreach($arraychacra as $chacraarray)
			{
				$chackradetails[$chacraarray]=$this->model_catalog_checkingform->getchacrasdetails($uid,$chacraarray,$position);
			}

			$chakraArr1[] = '';
			$chakraArr2[] = '';
			foreach($chackradetails as $chakraData) 
			{
				if($chakraData['lowangel'] != 0  || $chakraData['hle'] == 'HLE') {
						   if($chakraData['lowangel'] != 0) {
								$chakraValue = $chakraData['lowangel'];
						   } else {
								$chakraValue = 100;
						   }
					$chakraArr1[] = $chakraData['chakras'];
					$chakraArr2[] = (float)$chakraValue;						
				}
			}
			
			//echo '<pre>'; print_r($envdetails); exit;
			$this->data['chackradetails']=$chackradetails;
			$this->data['plantdetails']=$plantdetails;
			$this->data['envdetails']=$envdetails;
			$this->data['isexists']=$isexists;

			$this->data['envchartdetails01']= json_encode($envArr1);
			$this->data['plantdetails01']= json_encode($plantArr1);
			$this->data['chakradetails01']= json_encode($chakraArr1);
			$this->data['envchartdetails02']= json_encode($envArr2);
			$this->data['plantdetails02']= json_encode($plantArr2);
			$this->data['chakradetails02']= json_encode($chakraArr2);
			
			}
		
		$this->data['position'] = $position;
		
		
		$this->children = array(
            'common/header',
            'common/footer'
        );      
		$this->data['tabclicked']=$_POST['tabclicked'];
        $this->response->setOutput($this->render());
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . 'common/environmental.tpl')) {
            $this->template = $this->config->get('config_template') . 'common/environmental.tpl';
        } else {
            $this->template = 'common/environmental.tpl';
        }
        
		
    }
}
?>